#include "Program.h"

#include <compilation/task/GraphTask.h>


namespace compilation
{


void
Program::exportToDot(const std::string &filename)
{
  UNSET_DEBUG_FOR_VISITORS();

  GraphAgenda::instruction_handler_visitor_type ghv =
      GraphAgenda::instruction_handler_visitor_type
      ::build_visitor<GraphHandler>();

  GraphAgenda::instruction_propagator_visitor_type gpv =
      GraphAgenda::instruction_propagator_visitor_type
      ::build_visitor<DefaultInstructionPropagator
      <GraphTask, GraphAgenda>::type>();

  for (std::set<Function>::const_iterator functionIter = m_functions.begin();
       functionIter != m_functions.end(); ++functionIter)
  {
    GraphAgenda agenda(ghv, gpv, *functionIter);
    execute(agenda);
    std::stringstream ss;
    ss << filename << '.' << functionIter->getName() << ".dot";
    agenda.saveAs(ss.str());
  }
}


} // compilation
